﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using University.Workshop.DataAccess;
using University.Workshop.Model;

namespace University.Workshop.Business
{
    public static class PatientManager
    {
        public static DataTable LoadDataGridViewPatient()
        {
            return PatientDataAccess.LoadDataGridViewPatient();
        }
        public static bool DisablePatient(string idPatient)
        {
            return PatientDataAccess.DisablePatient(idPatient);
        }
        public static bool ModifyPatient(string idPatient, Patient patient)
        {
            return PatientDataAccess.ModifyPatient(idPatient, patient);
        }

        public static DataTable LoadDataGridViewSearchPatient(string searchPatient)
        {
            return PatientDataAccess.LoadDataGridViewSearchPatient(searchPatient);
        }

        public static bool InsertNewPatient(Patient newPatient)
        {
            if (newPatient != null)
            {
                if (newPatient.ImagePatient == null)
                {
                    newPatient.ImagePatient = "anonimos.jpg";
                    return PatientDataAccess.InsertNewPatient(newPatient);
                }
                else
                {
                    return PatientDataAccess.InsertNewPatient(newPatient);
                }
            }
            else
                return false;
        }

        public static string LoadDataPatient(string searchPatient)
        {
            DataSet dataSet = PatientDataAccess.LoadDataPatient(searchPatient);
            string patient;
            if (dataSet != null)
            {
                patient = dataSet.Tables[0].Rows[0]["LastName"].ToString();
                patient +=","+ dataSet.Tables[0].Rows[0]["FirstName"].ToString();
                return patient;
            }
            else
            {
                return "Patient not Exist";
            }            
        }
    }
}
